import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import {longLimtVal, longLimtValAndNotBlank, rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {h} from 'vue';
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '设备序列号',
    align:"center",
    dataIndex: 'code'
   },
   {
    title: '设备名称',
    align:"center",
    dataIndex: 'name'
   },
   {
    title: '设备状态',
    align:"center",
    dataIndex: 'state_dictText',
     customRender:({value,record})=>{
      if(value=='离线') {
        return h('div', {
          style: {"background": "red", "width":"18px","height":"18px","border-radius":"50%","margin":"0 auto"}
        });
      }
      else{
        return h('div', {
          style: {"background": "green", "width":"18px","height":"18px","border-radius":"50%","margin":"0 auto"}
        });
      }

     }
   },
   {
    title: '是否激活',
    align:"center",
    dataIndex: 'active_dictText',
     customRender:({value,record})=>{
       if(value=='未激活') {
         return h('div', {
           style: {"background": "red", "width":"18px","height":"18px","border-radius":"50%","margin":"0 auto"}
         });
       }
       else{
         return h('div', {
           style: {"background": "green", "width":"18px","height":"18px","border-radius":"50%","margin":"0 auto"}
         });
       }

     }
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "设备序列号",
      field: 'code',
      component: 'Input',
      //colProps: {span: 6},
 	},
	{
      label: "设备名称",
      field: 'name',
      component: 'JInput',
      //colProps: {span: 6},
 	},
	{
      label: "是否激活",
      field: 'active',
      component: 'JDictSelectTag',
    componentProps:{
        dictCode:"visit_dev_active"
    }
      //colProps: {span: 6},
 	},
  {
    label: "是否在线",
    field: 'state',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "visit_dev_state"
    },
  }
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '设备序列号',
    field: 'code',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        {
          validator: (_, value) => {
            return longLimtValAndNotBlank(value,15)
          },
        },
      ];
    },
  },
  {
    label: '设备名称',
    field: 'name',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        {
          validator: (_, value) => {
            return longLimtValAndNotBlank(value,30)
          },
        },
      ];
    },
  },
  {
    label: '设备状态',
    field: 'state',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:"visit_dev_state",
      stringToNumber:true,
    },
    defaultValue:0,
    show:false
  },
  {
    label: '激活状态',
    field: 'active',
    component: 'Input',
    defaultValue:"0",
    show:false

  },
  {
    label: 'mac地址',
    field: 'mac',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        {
          validator: (_, value) => {
            return longLimtVal(value,20)
          },
        },
      ];
    },
  },
  {
    label: 'ip地址',
    field: 'ip',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        {
          validator: (_, value) => {
            return longLimtVal(value,15)
          },
        },
      ];
    },
    defaultValue:"0.0.0.0"
  },
  {
    label: '端口',
    field: 'port',
    component: 'InputNumber',
    dynamicRules: ({model,schema}) => {
      return [
        {
          validator: (_, value) => {
            return longLimtVal(value,8)
          },
        },
      ];
    },
    defaultValue:'0'
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  code: {title: '设备序列号',order: 0,view: 'text', type: 'string',},
  name: {title: '设备名称',order: 1,view: 'text', type: 'string',},
  state: {title: '设备状态',order: 2,view: 'number', type: 'number',},
  active: {title: '是否激活',order: 6,view: 'number', type: 'number',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
